require(['./config'],()=>{
    require(['jquery'],($)=>{
        class Register{
            constructor(){
                this.register()
            }
            register(){ 
                $('.registerBtn').on('click',()=>{
                    let registerName = $('#registerName').val();                  
                    let registerPwd = $('#registerPassword').val();
                    let userinfo = {registerName,registerPwd}
                    var userList = localStorage.getItem('userList')
                    if (userList) {
                        console.log(userList)

                        const isExist = JSON.parse( userList).some(item=>{
                            return item.registerName==registerName
                        })
                        console.log(isExist);
                        
                        if(isExist){
                            alert('用户名已存在，请重新输入')
                        }else{
                            userList = JSON.parse(userList)
                            userList.push(userinfo)
                            localStorage.setItem('userList',JSON.stringify(userList))
                            alert('注册成功，即将跳转登录页')
                            location.href = '/html/login.html'
                        }

                    } else {
                        var arr = [userinfo]
                        localStorage.setItem('userList', JSON.stringify(arr))
                        alert('注册成功，即将跳转登录页')
                        location.href = '/html/login.html'
                    }

                })   
                
          }
        
        }
        new Register()
    })
})